<?php
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = '87';

		function do_get()
		{
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );

			$cate = load( 'biz.cate' );
			$result = $cate->getcatealllist();
			$template->assign( 'cate_data', $result );
			if ( isset( $this->input['cate_id'] ) && $this->input['cate_id'] > 0 )
			{
				$cate_data = $cate->get( array( 'id'=>$this->input['cate_id'] ) );

				if ( ! empty( $cate_data ) )
				{
					//加载基本数据模型
					$module_data = array();
					$html_module = load( 'biz.html_module' );
					$module_data_base = $html_module->base( $this->input );

					//根据栏目类型加载相应的数据模型
					$argument = load( 'biz.argument' );
					switch ( $cate_data['module_type_id'] )
					{
						case $argument->CM_NEWS:
							$module_data_ext = $html_module->news( $this->input );
							break;

						case $argument->CM_PHOTO:
							$module_data_ext = $html_module->photo( $this->input );
							break;

						case $argument->CM_VIDEO:
							$module_data_ext = $html_module->video( $this->input );
							break;

							default:
								$module_data_ext = $html_module->news( $this->input );
					}
					$module_data = array_merge( $module_data_base, $module_data_ext );

					$template->assign( 'module_data', $module_data );
				}
			}

			$template->assign( 'current_url', config( 'current_url' ) );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			$template->appoint( $this->input );
			echo $template->parse( 'add_html.php' );
		}

		/**
		 * description
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function do_post()
		{
			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'list_html.php';
			unset( $this->input['reference'] );

			$html = load( 'biz.html' );
			$result = $html->add( $this->input );

			if ( $result['success'] )
			{
				$this->prompt( '添加成功', array( array( 'url' => config( 'domain.admin' ) . 'add_html.php?reference=' . urlencode( $url ), 'name' => '继续创建' ), array( 'url' => 'list_html.php', 'name' => '返回列表' ) ) );
			}
			else
			{
				$this->prompt( '添加失败', $this->transform( $result['message'], config( 'server.HTTP_REFERER' ) ) );
			}
		}

		//格式化传入参数
		function format( $value )
		{
			if ( get_magic_quotes_gpc() )
			{
				$value = stripslashes( $value );
			}

			return trim( preg_replace( '/\'/', '\"', $value ) ) ;
		}

	}

	$action = new action();
	$action->run();
?>